package com.dididoctor.patient.Activity.Usercentre.Userinfo;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Activity.Usercentre.EditPhoneActivity;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.MV.EduActivity;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Ui.TimeWheel.DatePicker;
import com.dididoctor.patient.Ui.TimeWheel.MyDatePicker;
import com.dididoctor.patient.Ui.Wheel.StrericWheelAdapter;
import com.dididoctor.patient.Ui.Wheel.WheelView;
import com.dididoctor.patient.Ui.cityList.CityBean;
import com.dididoctor.patient.Utils.ABAppUtil;
import com.dididoctor.patient.Utils.ABFileUtil;
import com.dididoctor.patient.Utils.LoaderImage;
import com.dididoctor.patient.Utils.MyToast;
import com.dididoctor.patient.Utils.PictureUtil;
import com.dididoctor.patient.Utils.Util;
import com.dididoctor.patient.Utils.asynchttp.AsyncHttpClient;
import com.dididoctor.patient.Utils.asynchttp.AsyncHttpResponseHandler;
import com.dididoctor.patient.Utils.asynchttp.RequestParams;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;

/**
 * Created by Administrator on 2016/4/4.text
 */
public class UserInfoActivity extends EduActivity implements UserInfoView {

    private TextView mTvSex, mTvDate, mTvPhone, mTvCity, mTvSubmit;
    private EditText mEtName, mEtCard, mEtAddress;
    private String phone = "", name = "", headPic = "", sex = "", birth = "", idNo = "", cityId = "", address = "", cityName = "";
    private String[] genders = new String[]{"女", "男"};
    private UserInfoPresenter presenter;
    private WheelView mWeelView;
    private StrericWheelAdapter mWheelAdapter;
    public int which = 0;
    private RelativeLayout mRelWheel, mLayHead, mRelCameraAlbum;
    private LoaderImage loaderImage;

    private Button mBtnCamera, mBtnAlbum, mBtnCancel, mBtnWheelConfirm,
            mBtnWheelCancel;
    private File capturePath = null;
    private final static int TO_CAMEIA = 105;
    private final static int TO_PHOTO = 106;
    private final static int TO_ZOOM_PHOTO = 107;
    private final static int TO_ZOOM = 109;
    private final static int EDITOR_CITY = 108;
    private ImageView mIvHead;
    //整体布局
    private RelativeLayout Rl_all;
    private String tempPath;

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_user_info);
    }

    @Override
    public void init() {
        //初始化控件
        initview();
        //初始化头部
        inithead();
        //时钟初始化
        calendar = Calendar.getInstance();
    }

    private void inithead() {
        ((TextView) findViewById(R.id.tv_title)).setText("个人信息");
        mTvSubmit = (TextView) findViewById(R.id.tv_finish);
        mTvSubmit.setVisibility(View.VISIBLE);
        mTvSubmit.setText("保存");
        mTvSubmit.setOnClickListener(this);
        presenter = new UserInfoPresenter(this, this);
        presenter.getuserinfo();
    }

    private void initview() {
        Rl_all = (RelativeLayout) findViewById(R.id.Rl_all);
        mTvSex = (TextView) findViewById(R.id.tv_sex);
        mTvDate = (TextView) findViewById(R.id.tv_date);
        mTvPhone = (TextView) findViewById(R.id.tv_phone);
        mTvCity = (TextView) findViewById(R.id.tv_city);
        mEtName = (EditText) findViewById(R.id.et_name);
        mEtAddress = (EditText) findViewById(R.id.et_address);
        mEtCard = (EditText) findViewById(R.id.et_card);
        findViewById(R.id.rel_sex).setOnClickListener(this);
        findViewById(R.id.rel_date).setOnClickListener(this);
        findViewById(R.id.rel_phone).setOnClickListener(this);
        findViewById(R.id.rel_city).setOnClickListener(this);
        //头像
        mLayHead = (RelativeLayout) findViewById(R.id.lay_head);
        mLayHead.setOnClickListener(this);
        //滚轴确定取消按钮
        mBtnWheelConfirm = (Button) findViewById(R.id.btn_wheel_confirm);
        mBtnWheelConfirm.setOnClickListener(this);
        mBtnWheelCancel = (Button) findViewById(R.id.btn_wheel_cancel);
        mBtnWheelCancel.setOnClickListener(this);
        //相机图册选择
        mRelCameraAlbum = (RelativeLayout) findViewById(R.id.rel_camera_album);
        mBtnCamera = (Button) findViewById(R.id.btn_camera);
        mBtnCamera.setOnClickListener(this);
        mBtnAlbum = (Button) findViewById(R.id.btn_album);
        mBtnAlbum.setOnClickListener(this);
        findViewById(R.id.btn_cancel).setOnClickListener(this);
        //头像
        mIvHead = (ImageView) findViewById(R.id.iv_head);
        loaderImage = new LoaderImage(this);

        mRelWheel = (RelativeLayout) findViewById(R.id.rel_wheel);
        mWeelView = (WheelView) findViewById(R.id.weelview);
        int textSize = dip2px(UserInfoActivity.this, 24);
        mWeelView.TEXT_SIZE = textSize;

    }

    @Override
    public void getUserInfo(Userinfo userinfo) {
        loaderImage.load(mIvHead, userinfo.getHeadPic(), new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                mIvHead.setImageResource(R.drawable.img_userdefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                mIvHead.setImageResource(R.drawable.img_userdefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });
        if (!Util.isEmpty(userinfo.getName())) {
            mEtName.setText(userinfo.getName());
        }

        if (!Util.isEmpty(userinfo.getIdNo())) {
            mEtCard.setText(userinfo.getIdNo());
        }
        if (!Util.isEmpty(userinfo.getAddress())) {
            mEtAddress.setText(userinfo.getAddress());
        }
        String sex = Util.isEmpty(userinfo.getSex()) ? "请选择" : userinfo.getSex();
        if (!Util.isEmpty(sex)) {
            if ("0".equals(sex)) {
                mTvSex.setText("女");
            } else {
                mTvSex.setText("男");
            }
        }
        mTvDate.setText(Util.isEmpty(userinfo.getBirth()) ? "请选择" : userinfo.getBirth());
        mTvCity.setText(Util.isEmpty(userinfo.getCityName()) ? "请选择" : userinfo.getCityName());
        mTvPhone.setText(Util.isEmpty(userinfo.getPhone()) ? "请选择" : userinfo.getPhone());
        headPic = userinfo.getHeadPic();
        cityId = userinfo.getCity();
    }


    @Override
    protected void onResume() {
        super.onResume();
        mTvPhone.setText(Token.getPhone());
    }

    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.tv_finish:
                ABAppUtil.hideSoftInput(UserInfoActivity.this);
                getviewdata();
                if (isOkSave()) {
                    if (idNo.length() == 15 || idNo.length() == 18) {
                        presenter.updateuserinfo(phone, name, headPic, sex, birth, idNo, cityId, address);
                    } else {
                        showToastMessage("身份证号输入错误");
                    }

                }
                break;
            case R.id.rel_sex:
                ABAppUtil.hideSoftInput(UserInfoActivity.this);
                which = 0;
                mWheelAdapter = new StrericWheelAdapter(genders);
                mWeelView.setAdapter(mWheelAdapter);
                mRelWheel.setVisibility(View.VISIBLE);
//                showToastMessage("请选择性别");
                break;
            case R.id.rel_date:
                ABAppUtil.hideSoftInput(UserInfoActivity.this);
                getYearMD(mTvDate);
//                datePickerShow(mTvDate);
                break;
            case R.id.rel_phone:
                Intent intent = new Intent(this, EditPhoneActivity.class);
                startActivity(intent);
                break;
            case R.id.rel_city:
                Intent intentCity = new Intent(this, EditCityActivity.class);
                startActivityForResult(intentCity, EDITOR_CITY);
                break;
            case R.id.btn_wheel_confirm:
                mTvSex.setText(genders[mWeelView.getCurrentItem()]);
                mRelWheel.setVisibility(View.GONE);
                break;
            case R.id.btn_wheel_cancel:
                mRelWheel.setVisibility(View.GONE);
                break;
            case R.id.lay_head:
                mRelCameraAlbum.setVisibility(View.VISIBLE);
                break;
            case R.id.btn_camera:
                getfromePhoto();
                break;
            case R.id.btn_album:
                doPickPhotoFromGallery();
                break;
            case R.id.btn_cancel:
                mRelCameraAlbum.setVisibility(View.GONE);
                break;
        }
    }


    // 拍照获取图片
    protected void getfromePhoto() {
        this.mRelCameraAlbum.setVisibility(View.GONE);
        // 执行拍照前，应该先判断SD卡是否存在
        String SDState = Environment.getExternalStorageState();

        if (SDState.equals(Environment.MEDIA_MOUNTED)) {

            Intent takePictureIntent = new Intent(
                    MediaStore.ACTION_IMAGE_CAPTURE);
            try {
                capturePath = PictureUtil.createImageFile();
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        Uri.fromFile(capturePath));
                startActivityForResult(takePictureIntent, TO_CAMEIA);
            } catch (IOException e) {
                e.printStackTrace();
            }

        } else {
            Toast.makeText(this, "内存卡不存在", Toast.LENGTH_LONG).show();
        }

    }

    /**
     * 相册选择
     */
    protected void doPickPhotoFromGallery() {
        this.mRelCameraAlbum.setVisibility(View.GONE);
        Intent albumIntent = new Intent(Intent.ACTION_PICK);
        albumIntent.setType("image/*");
        startActivityForResult(albumIntent, TO_PHOTO);
    }

    /**
     * 裁剪图片
     *
     * @param uri
     */
    private void startPhotoZoom(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
        intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
        intent.putExtra("aspectY", 1);// x:y=1:1
        intent.putExtra("outputX", 800);// 图片输出大小
        intent.putExtra("outputY", 800);
        intent.putExtra("output", uri);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", false);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra("noFaceDetection", true); // no face detection
        intent.putExtra("outputFormat", "JPEG");// 返回格式
        startActivityForResult(intent, TO_ZOOM_PHOTO);
    }

    /**
     * 裁剪图片
     *
     * @param in
     */
    private void startPhotoZoomPhoto(Uri in, Uri out) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(in, "image/*");
        intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
        intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
        intent.putExtra("aspectY", 1);// x:y=1:1
        intent.putExtra("outputX", 800);// 图片输出大小
        intent.putExtra("outputY", 800);
        intent.putExtra("output", out);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", false);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra("noFaceDetection", true); // no face detection
        intent.putExtra("outputFormat", "JPEG");// 返回格式
        startActivityForResult(intent, TO_ZOOM);
    }

    public static String getTempImagePath() {
        String tempPath = ABFileUtil.getAppTmpPath() + "/" + System.currentTimeMillis() + ".jpg";//产生临时路径
        return tempPath;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case TO_CAMEIA:
                    startPhotoZoom(Uri.fromFile(capturePath));
                    break;
                case TO_PHOTO:
                    if (data == null) {
                        return;
                    }
                    if (tempPath == null) {
                        tempPath = getTempImagePath();
                    }
                    Uri uri = data.getData();
                    String realPathFromURI = getRealPathFromURI(uri);
                    if (!Util.isEmpty(realPathFromURI)) {
                        capturePath = new File(realPathFromURI);
                        Uri out = Uri.fromFile(new File(tempPath));
                        startPhotoZoomPhoto(Uri.fromFile(capturePath), out);
                    } else {
                        MyToast.DefaultmakeText(UserInfoActivity.this, "相册选择图片失败", 0);
                    }
                    break;
                case TO_ZOOM_PHOTO:
                    try {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        options.inSampleSize = 2;
                        Bitmap bitmap = BitmapFactory.decodeFile(
                                capturePath.getPath(), options);
                        // 压缩图片
                        // bitmap = compressImage(bitmap,500);

                        if (bitmap != null) {

                            // 保存图片
                            FileOutputStream fos = null;
                            fos = new FileOutputStream(capturePath);
                            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                            fos.flush();
                            fos.close();
                            uploadpic(capturePath, bitmap);

                        }
                    } catch (Exception e) {
                        // TODO: handle exception

                    }
                    break;
                case TO_ZOOM: {
                    try {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        options.inSampleSize = 2;
                        Bitmap bitmap = BitmapFactory.decodeFile(
                                new File(tempPath).getPath(), options);
                        // 压缩图片
                        // bitmap = compressImage(bitmap,500);

                        if (bitmap != null) {

                            // 保存图片
                            FileOutputStream fos = null;
                            fos = new FileOutputStream(new File(tempPath));
                            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                            fos.flush();
                            fos.close();
                            uploadpic(new File(tempPath), bitmap);

                        }
                    } catch (Exception e) {
                        this.showToastMessage(e.getMessage());
                    }
                }
                break;
                case EDITOR_CITY:
                    CityBean cityBean = (CityBean) data.getSerializableExtra("hotcity");
                    cityName = cityBean.getCityName();
                    if (cityName != null && !cityName.equals("")) {
                        mTvCity.setText(cityName);
                    }

                    String cityCode = cityBean.getCityCode();
                    if (!Util.isEmpty(cityCode)) {
                        cityId = cityCode;
                    }
                    break;
                default:
                    break;
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 上传图片
     *
     * @param bitmap
     * @param file
     */
    private void uploadpic(File file, final Bitmap bitmap) {
        // final File file = new File(path);
        if (file.exists() && file.length() > 0) {
            AsyncHttpClient client = new AsyncHttpClient();
            RequestParams params = new RequestParams();
            try {
                params.put("userId", Token.getId());
                params.put("file", file);
                params.put("token", Token.getToken());
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            client.post(ConstantValue.uploadImgUrl, params,
                    new AsyncHttpResponseHandler() {
                        @Override
                        public void onStart() {
                            super.onStart();
                        }

                        @Override
                        public void onSuccess(int statusCode, Header[] headers,
                                              String content) {
                            int statusCode2 = statusCode;
                            Header[] headers2 = headers;
                            String content2 = content;
                            if (content != null && !content.equals("")) {
                                JSONObject dataJson;
                                try {
                                    dataJson = new JSONObject(content);
                                    String status = dataJson
                                            .getString("status");
                                    if (status.equals("1")) {
                                        MyToast.DefaultmakeText(getApplicationContext(), "头像上传成功", 0);
                                        String string = dataJson.getString("data");
                                        JSONObject js = new JSONObject(string);
                                        headPic = js.getString("headPic");
                                        // 显示图片
                                        mIvHead.setImageBitmap(bitmap);
                                    } else {
                                        MyToast.DefaultmakeText(getApplicationContext(), "头像上传失败", 0);
                                    }

                                } catch (JSONException e) {

                                    e.printStackTrace();
                                }
                            }

                        }

                        @Override
                        public void onFailure(Throwable error, String content) {
                            MyToast.DefaultmakeText(getApplicationContext(), "失败", 0);
                            super.onFailure(error, content);
                        }

                        @Override
                        public void onFinish() {

                            super.onFinish();
                        }

                    });
        } else {
            MyToast.DefaultmakeText(getApplicationContext(), "文件不存在", 0);
        }

    }


    public String getRealPathFromURI(Uri contentUri) {
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }


    @Override
    public void savesucced() {
        showToastMessage("保存成功");
        Token.setName(name);
        Token.setHeadPic(headPic);
        Token.setSex(sex);
        Token.setPhone(phone);
        Token.setCity(cityId);
        Token.setAddress(address);
        finish();
    }

    @Override
    public void savefail() {
        showToastMessage("保存失败");
    }


    @Override
    public void getUserInfofail() {
    }

    public boolean isOkSave() {
        if (Util.isEmpty(name)) {
            showToastMessage("请输入姓名");
            return false;
        } else if (Util.isEmpty(sex)) {
            showToastMessage("请选择性别");
            return false;
        } else if (Util.isEmpty(birth)) {
            showToastMessage("请选择出生日期");
            return false;
        } else if (Util.isEmpty(idNo)) {
            showToastMessage("请输入身份证号");
            return false;
        } else if (Util.isEmpty(cityId)) {
            showToastMessage("请选择城市");
            return false;
        } else if (Util.isEmpty(address)) {
            showToastMessage("请输入完整地址");
            return false;
        } else {
            return true;
        }
    }

    private void getviewdata() {
        phone = mTvPhone.getText().toString();
        name = mEtName.getText().toString();
        if ("男".equals(mTvSex.getText().toString())) {
            sex = "1";
        } else if ("女".equals(mTvSex.getText().toString())) {
            sex = "0";
        }
        idNo = mEtCard.getText().toString();
        address = mEtAddress.getText().toString();
        birth = "请选择".equals(mTvDate.getText().toString()) ? "" : mTvDate.getText().toString();
    }


    /**********************************************
     * 日期滚轴后期封装
     *****************************************************/
    private String selectDate, selectTime;
    private Calendar calendar;
    private MyDatePicker tp_test;
    private TextView tv_ok, tv_cancel;    //确定、取消button
    private PopupWindow pw;
    private int dateYear, dateMonth, dateDay;
    //选择时间与当前时间，用于判断用户选择的是否是以前的时间
    private int currentHour, currentMinute, currentDay, selectHour, selectMinute, selectDay;

    protected void getYearMD(final TextView mTvDate) {
        View view = View.inflate(UserInfoActivity.this, R.layout.dialog_select_time, null);
        selectDate = calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-"
                + calendar.get(Calendar.DAY_OF_MONTH) + "-";
        //选择时间与当前时间的初始化，用于判断用户选择的是否是以前的时间，如果是，弹出toss提示不能选择过去的时间
        selectDay = currentDay = calendar.get(Calendar.DAY_OF_MONTH);
        selectMinute = currentMinute = calendar.get(Calendar.MINUTE);
        selectHour = currentHour = calendar.get(Calendar.HOUR_OF_DAY);

        selectTime = currentHour + "点" + ((currentMinute < 10) ? ("0" + currentMinute) : currentMinute) + "分";
        tp_test = (MyDatePicker) view.findViewById(R.id.tp_test);
        tv_ok = (TextView) view.findViewById(R.id.tv_ok);
        tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        //设置滑动改变监听器
//        dp_test.setOnChangeListener(dp_onchanghelistener);
        tp_test.setOnChangeListener(tp_onchanghelistener);
        pw = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
//				//设置这2个使得点击pop以外区域可以去除pop
//				pw.setOutsideTouchable(true);
//				pw.setBackgroundDrawable(new BitmapDrawable());

        //出现在布局底端
        pw.showAtLocation(Rl_all, 0, 0, Gravity.END);

        //点击确定
        tv_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                if (selectDay == currentDay) {    //在当前日期情况下可能出现选中过去时间的情况
                    if (selectHour < currentHour) {
                        MyToast.DefaultmakeText(getApplicationContext(), "不能选择过去的时间\n        请重新选择", 0);
                    } else if ((selectHour == currentHour) && (selectMinute < currentMinute)) {
                        MyToast.DefaultmakeText(getApplicationContext(), "不能选择过去的时间\n        请重新选择", 0);
                    } else {
                        Calendar now = Calendar.getInstance();
                        if (dateYear > now.get(Calendar.YEAR)) {
                            showToastMessage("不能选择将来的时间\n" +
                                    "        请重新选择");
                        } else {
                            if (dateYear == now.get(Calendar.YEAR)) {
                                if (dateMonth > (now.get(Calendar.MONTH) + 1)) {
                                    showToastMessage("不能选择将来的时间\n" +
                                            "        请重新选择");
                                } else {
                                    if (dateMonth == (now.get(Calendar.MONTH) + 1)) {
                                        if (dateDay > now.get(Calendar.DAY_OF_MONTH)) {
                                            showToastMessage("不能选择将来的时间\n" +
                                                    "        请重新选择");
                                        } else {
                                            mTvDate.setText(selectDate);
                                        }
                                    } else {
                                        mTvDate.setText(selectDate);
                                    }
                                }
                            } else {
                                mTvDate.setText(selectDate);
                            }
                        }
                        pw.dismiss();
                    }
                } else {
                    mTvDate.setText(selectDate);
                    pw.dismiss();
                }
            }
        });

        //点击取消
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                pw.dismiss();
            }
        });
    }

    //listeners
    DatePicker.OnChangeListener dp_onchanghelistener = new DatePicker.OnChangeListener() {
        @Override
        public void onChange(int year, int month, int day, int day_of_week) {
            selectDay = day;
            selectDate = year + "-" + month + "-" + day;
        }
    };
    MyDatePicker.OnChangeListener tp_onchanghelistener = new MyDatePicker.OnChangeListener() {
        @Override
        public void onChange(int year, int month, int day, int day_of_week) {
            dateYear = year;
            dateMonth = month;
            dateDay = day;
            selectDate = year + "-" + month + "-" + day;
        }

//        @Override
//        public void onChange(int hour, int minute) {
//            selectTime = hour + "点" + ((minute < 10) ? ("0" + minute) : minute) + "分";
//            selectHour = hour;
//            selectMinute = minute;
//        }
    };

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mRelCameraAlbum.getVisibility() == View.VISIBLE) {
                mRelCameraAlbum.setVisibility(View.GONE);
            } else {
                finish();
            }
        }
        return true;
    }

}

